package pw_coding

import "path"

func entities2Module(es []EntityStruct, filesuffix, tplcode, code string) *Folder {
	rootPath := GetWorkDir()
	// 根包
	m := &Folder{}
	m.Name = code
	m.FPath = rootPath
	files := make([]File, 0)
	for _, e := range es {
		f := entity2file(e, filesuffix, tplcode)
		files = append(files, *f)
	}
	m.Files = files
	return m
}

func entity2file(es EntityStruct, filesuffix, tplcode string) *File {
	rootPath := GetWorkDir()
	file := &File{}
	file.Name = es.Name
	file.FileSuffix = filesuffix
	file.TplCode = tplcode
	file.FOffsetPath = es.Package
	file.FPath = path.Join(rootPath, file.FOffsetPath)
	file.Args = es
	return file
}
